import { ipcMain } from 'electron'
import { getList, openSerialPort } from '../../utils/serialport/index'

export const SerialPortSend = () => {
  // 串口连接实例
  let serialPortConnect

  // 查询串口列表
  ipcMain.on('getSerialPortList', (e, arg) => {
    getList().then((res) => {
      console.log('select serial port list!')
      e.reply('SerialPort-getList', res)
    })
  })

  // 打开串口
  ipcMain.on('openSerialPort', (e, arg) => {
    serialPortConnect = openSerialPort(arg, (openResult) => {
      e.reply('SerialPort-openSerialPort', openResult)
    })
  })
}
